I am working on a web server project on the ESP8266, using Platform and the Arduino libraries.
My dependencies include ESP8266WiFi, ESP8266WebServer, tzapu/WiFiManager.
In my serial monitor, I keep seeing strange prints I did not put there myself. Here is an example :
:wr 57 0
:wrc 57 57 0
:wr 16 0
:wrc 16 16 0
:wr 17 0
:wrc 17 17 0
:wr 669 0
:wrc 669 669 0
:wr 269 0
:wrc 269 269 0
:wr 9 0
:wrc 9 9 0
:ack 57
:ack 536
:ack 444
:close
Does anybody know what these are, where they come from, and how to get rid of them ?
Here is part of my code (setup() in in main.cpp)
void setup(void) {
/* Set up logger */
gLogger = &Logger::instance();
/* Init relay */
gRelay = new elec::Relay(LED_DIO, elec::RELAY_MODE_NORMAL);
/* Init Switch */
gSwitch = new elec::Switch(SWITCH_DIO);
/* Init WiFi manager */
gWiFiMgr = new WiFiManager;
/** Set callback that gets called when connecting
* to previous WiFi fails,
* and enters Access Point mode */
gWiFiMgr->setAPCallback(configModeCallback);
/* Disable debug mode for the WiFiManager */
gWiFiMgr->setDebugOutput(false);
if(!gWiFiMgr->autoConnect(AP_NAME, AP_PASSWD)) {
*gLogger << "[ERROR] Failed to connect to WiFi !" << endlog;
ESP.reset();
delay(1000U);
}
*gLogger << "[BOOT ] Successfully connected to " << WiFi.SSID() << endlog;
*gLogger << "[BOOT ] IPv4 Address : " << WiFi.localIP().toString() << endlog;
/* Set up web server */
gServer = new WiFiServer(80U);
gServer->begin();
/* End of setup */
*gLogger << "[BOOT ] System booted !" << endlog;
}
In my case this was due to enabling "Debug Level: CORE" in Arduino IDE. Once I set it to None, these stopped.
Related
I'm working on my first ESP32 project using a DFRobot Firebeetle 2 (ESP32-WROOM-32E) and the Arduino IDE (configured as per DFRobot's instructions). I'm trying creating a Telegram bot which will send a message when the temperature exceeds a certain value. This part is working in the loop() method, but now I'm trying to add a 'status button' which triggers an interrupt to send a status message. I plan to use the ESP32's sleep function, hence using an interrupt rather than checking the button in loop() - I am aware that loop() doesn't execute when using sleep. The problem is sending a message in the interrupt method is causing an error, but I don't know how to resolve it.
If I reduce minStatusMsgInterval to 250 and call SendStatusMessage(); at the end of setup() I receive the message, so the function works, just not when it's called from an interrupt. The error mentions wdt timeout so I'm thinking bot.sendMessage() is taking too long? But if that is the case, I can't make it any quicker, so is there another way to achieve this? or have I misinterpreted the error completely?
#include <WiFi.h>
#include "WiFiClientSecure.h"
#include <ESP32Time.h>
#include <DFRobot_DHT11.h>
#include <UniversalTelegramBot.h>
//WiFi
#define WLAN_SSID "ESP32Test"
#define WLAN_PASS "*********"
//WiFiFlientSecure for SSL/TLS support
WiFiClientSecure client;
//Time
ESP32Time rtc(0); // offset in seconds; 0 = GMT, 3600 = GMT+1
//Telegram
#define TELEGRAM_TOKEN "*********:*************************"
#define CHAT_ID "**********"
UniversalTelegramBot bot(TELEGRAM_TOKEN, client);
//Temperature
DFRobot_DHT11 DHT;
#define DHT11_PIN D11
//Buttons
#define ONBOARD_BUTTON_PIN 27 //ESP32 pin 27
#define STATUS_BUTTON_PIN D10 //ESP32 pin 12
int StatusButtonLastInterrupt = 0;
//Alerts
int alertValue = 27;
bool alertSent = false;
int minStatusMsgInterval = 5000;
void IRAM_ATTR SendStatusMessage() {
if (millis() - StatusButtonLastInterrupt < minStatusMsgInterval) return; //Prevent executing multiple times per button press or more frequent than required
String message = "Temperature Monitor Status\n\n";
message += "Internal temperature: " + String(DHT.temperature) + "C\n";
message += "Internal humidity: " + String(DHT.humidity) + "%\n";
//message += "System time: " + rtc.getDateTime(); // Causes ESP to crash and reset. Error: abort() was called at PC 0x40084cf7 on core 1
//TODO: Check WiFi is connected first - will need to connect when woken from sleep
bot.sendMessage(CHAT_ID, message, ""); // Causes ESP to crash and reset. Error: Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1).
StatusButtonLastInterrupt = millis();
}
void SyncNTP() {
Serial.print("Retrieving time: ");
configTime(0, 3600, "time.google.com"); // get UTC time via NTP
time_t now = time(nullptr);
while (now < 24 * 3600)
{
Serial.print(".");
delay(100);
now = time(nullptr);
}
rtc.setTime(now); //Set the time on the realtime clock
Serial.println(rtc.getDateTime());
}
void setup() {
pinMode(ONBOARD_BUTTON_PIN, INPUT_PULLUP);
pinMode(STATUS_BUTTON_PIN, INPUT);
Serial.begin(115200);
//Interrupts
attachInterrupt(STATUS_BUTTON_PIN, SendStatusMessage, FALLING);
// Connect to WiFi access point.
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
WiFi.mode(WIFI_MODE_STA);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
//Serial.print(".");
Serial.print("WiFi Status: ");
Serial.println(WiFi.status());
}
Serial.println();
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
SyncNTP();
}
void loop() {
DHT.read(DHT11_PIN);
Serial.print("temp:");
Serial.print(DHT.temperature);
Serial.print(" humi:");
Serial.println(DHT.humidity);
if (DHT.temperature >= alertValue)
{
if (!alertSent)
{
bot.sendMessage(CHAT_ID, "TEMPERATURE ALERT: Internal temperature is: " + String(DHT.temperature), "");
alertSent = true;
}
} else {
if (alertSent)
{
bot.sendMessage(CHAT_ID, "Alert Cleared: Internal temperature is: " + String(DHT.temperature), "");
alertSent = false; //Reset the flag when temperature drops below alertValue
}
}
delay(1000);
}
Serial Monitor Output:
Connecting to ESP32Test
WiFi Status: 6
WiFi Status: 6
WiFi Status: 6
WiFi Status: 6
WiFi Status: 3
WiFi connected
IP address: 192.168.1.2
Retrieving time: ....................Sun, Feb 19 2023 22:23:38
temp:25 humi:57
temp:24 humi:53
temp:24 humi:60
temp:24 humi:60
temp:24 humi:60
temp:24 humi:60
Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1).
Core 1 register dump:
PC : 0x40090362 PS : 0x00060f34 A0 : 0x8008f47e A1 : 0x3ffbeb00
A2 : 0x3ffde700 A3 : 0x3ffbd994 A4 : 0x00000004 A5 : 0xb33fffff
A6 : 0x00000001 A7 : 0x00000001 A8 : 0x3ffbd994 A9 : 0x3ffbd994
A10 : 0x00000019 A11 : 0x00000019 A12 : 0x3ffc3afc A13 : 0xb33fffff
A14 : 0x00000001 A15 : 0x00000001 SAR : 0x0000000f EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x400896b0 LEND : 0x400896c6 LCOUNT : 0xffffffff
Core 1 was running in ISR context:
EPC1 : 0x400e8e33 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x40090362
Backtrace:0x4009035f:0x3ffbeb000x4008f47b:0x3ffbeb20 0x4008de7c:0x3ffbeb40 0x40106ab7:0x3ffbeb80 0x400f408f:0x3ffbeba0 0x401071c5:0x3ffbebd0 0x40107464:0x3ffbebf0 0x400f379d:0x3ffbec40 0x400d49d2:0x3ffbec60 0x400d472d:0x3ffbeed0 0x400d483e:0x3ffbef00 0x400d6c31:0x3ffbef20 0x400d7ece:0x3ffbef80 0x400d8406:0x3ffbf000 0x4008139e:0x3ffbf070 0x400d93f5:0x3ffbf0d0 0x40084a8d:0x3ffbf0f0 0x40173c7f:0x3ffc78f0 0x400e82e9:0x3ffc7910 0x4008e417:0x3ffc7930
Core 0 register dump:
PC : 0x40090522 PS : 0x00060634 A0 : 0x8008fc1b A1 : 0x3ffb3290
A2 : 0x3ffbf108 A3 : 0x3ffb32ac A4 : 0x00060623 A5 : 0xb33fffff
A6 : 0x0000cdcd A7 : 0x0000abab A8 : 0x0000abab A9 : 0x0000abab
A10 : 0x3ffde770 A11 : 0x000000d0 A12 : 0x3ffc6948 A13 : 0xb33fffff
A14 : 0x00000001 A15 : 0x00000001 SAR : 0x00000011 EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x400896b0 LEND : 0x400896c6 LCOUNT : 0xffffffff
Backtrace:0x4009051f:0x3ffb32900x4008fc18:0x3ffb32d0 0x4008dd9c:0x3ffb32f0 0x401069c0:0x3ffb3330 0x40106d0e:0x3ffb3350 0x400f56bb:0x3ffb3370 0x400f5739:0x3ffb3390 0x400f812c:0x3ffb33b0 0x400f8211:0x3ffb33e0 0x40108557:0x3ffb3400 0x400f3f19:0x3ffb3420
ELF file SHA256: 0000000000000000
Rebooting...
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1412
load:0x40078000,len:13400
load:0x40080400,len:3672
entry 0x400805f8
Connecting to ESP32Test
In general, interrupt handlers need to do as little as possible and return as quickly as possible. Doing too much or calling unsafe functions (which almost all functions will be) leads to programs crashing exactly the way you saw.
Interrupts, as the name indicates, interrupt whatever code is running and execute the interrupt's handler. The handler has no idea what state the code that was interrupted is in. It could easily be in an inconsistent state while it's performing a computation; calling it while it's in an inconsistent state is likely to corrupt memory or cause it to crash or behave erratically. Unless software is specifically designed to be called from an interrupt handler you must assume it's not safe to do so.
As you noticed, the ESP32 requires an interrupt handler to be marked with the IRAM_ATTR attribute - this tells the ESP32 to always keep this code in "Instruction RAM" so that it's always available to execute. The ESP32 isn't able to pull code in from flash storage on demand to service an interrupt. That means that not only does the interrupt handler have to be in IRAM, all functions it calls must be as well. IRAM is a scarce resource, so you want to use as little of it as possible - calling Telegram from an interrupt handler means that not only does all of the Telegram code need to be in IRAM but the entire TCP/IP network stack needs to be. Which also means you'd have to modify every single function in the TelegramBot and network stack to be declared IRAM_ATTR.
Obviously that's not going to work.
Unless you really know what you're doing, the safest way to code an interrupt handler is to set a flag variable indicating there's work to be done, store any data that needs to be saved for the work in other variables and return.
In your case it would look something like this:
volatile boolean should_send_telegram_message = false;
void IRAM_ATTR SendStatusMessage() {
if (millis() - StatusButtonLastInterrupt < minStatusMsgInterval)
return; //Prevent executing multiple times per button press or more frequent than required
should_send_telegram_message = true;
}
void loop() {
if(should_send_telegram_message) {
should_send_telegram_message = false;
String message = "Temperature Monitor Status\n\n";
message += "Internal temperature: " + String(DHT.temperature) + "C\n";
message += "Internal humidity: " + String(DHT.humidity) + "%\n";
//message += "System time: " + rtc.getDateTime(); // Causes ESP to crash and reset. Error: abort() was called at PC 0x40084cf7 on core 1
//TODO: Check WiFi is connected first - will need to connect when woken from sleep
bot.sendMessage(CHAT_ID, message, ""); // Causes ESP to crash and reset. Error: Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1).
StatusButtonLastInterrupt = millis();
}
// do other loop() stuff
}
The volatile attribute on should_send_telegram_message tells the compiler that this variable may unexpectedly have its value changed (as the interrupt handler may do) so that the compiler will avoid doing certain optimizations that depend on the variable not unexpectedly changing.
I am trying to use a PN532 (v3) board with an Arduino UNO and libnfc for my university project. One problem I have stumbled upon is that libnfc-1.7.1 gives me the following error when I invoke nfc-list:
debug libnfc.general log_level is set to 3
debug libnfc.general allow_autoscan is set to false
debug libnfc.general allow_intrusive_scan is set to false
debug libnfc.general 1 device(s) defined by user
debug libnfc.general #0 name: "PN532 NFC Board on Arduino", connstring: "pn532_uart:/dev/ttyUSB0:115200"
nfc-list uses libnfc 1.7.1
debug libnfc.driver.pn532_uart Attempt to open: /dev/ttyUSB0 at 115200 bauds.
debug libnfc.bus.uart Serial port speed requested to be set to 115200 bauds.
debug libnfc.chip.pn53x Diagnose
debug libnfc.chip.pn53x Timeout value: 500
debug libnfc.bus.uart TX: 55 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00
debug libnfc.chip.pn53x SAMConfiguration
debug libnfc.chip.pn53x Timeout value: 1000
debug libnfc.bus.uart TX: 00 00 ff 03 fd d4 14 01 17 00
debug libnfc.bus.uart Timeout!
debug libnfc.driver.pn532_uart Unable to read ACK
error libnfc.driver.pn532_uart pn53x_check_communication error
debug libnfc.chip.pn53x InRelease
debug libnfc.bus.uart TX: 00 00 ff 03 fd d4 52 00 da 00
debug libnfc.bus.uart Timeout!
debug libnfc.driver.pn532_uart Unable to read ACK
debug libnfc.general Unable to open "pn532_uart:/dev/ttyUSB0:115200".
nfc-list: ERROR: Unable to open NFC device: pn532_uart:/dev/ttyUSB0:115200
I have no issues using the reader with Arduino, I can upload sketches and the reader interacts with tags. The reader is in SPI mode, and when I invoke nfc-list the LEDs blink, therefore the only thing I can think of is some sort of issue with libnfc.
I hope someone can help,any suggestions would be amazing! :)
Thank you!
Connections
PN532 V3
Arduino.1
Arduino.2
File Configurations
/etc/nfc/libnfc.conf
# Allow device auto-detection (default: true)
# Note: if this auto-detection is disabled, user has to set manually a device
# configuration using file or environment variable
allow_autoscan = false
# Allow intrusive auto-detection (default: false)
# Warning: intrusive auto-detection can seriously disturb other devices
# This option is not recommended, user should prefer to add manually his device.
allow_intrusive_scan = false
# Set log level (default: error)
# Valid log levels are (in order of verbosity): 0 (none), 1 (error), 2 (info), 3 (debug)
# Note: if you compiled with --enable-debug option, the default log level is "debug"
log_level = 3
# Manually set default device (no default)
# To set a default device, you must set both name and connstring for your device
# Note: if autoscan is enabled, default device will be the first device available in device
list.
device.name = "PN532 NFC Board on Arduino"
device.connstring = "pn532_uart:/dev/ttyUSB0:115200"
uartnfc.info
#include <PN532.h>
#define SCK 13
#define MOSI 11
#define SS 10
#define MISO 12
PN532 nfc(SCK, MISO, MOSI, SS);
uint8_t buffer[32];
void setup(void) {
Serial.begin(115200); //460800, 115200
Serial.flush();
nfc.begin();
}
void loop(void) {
int b = Serial.available();
if (b >= 5){
Serial.readBytes((char*)buffer, 5);
if(buffer[0] == 0x55){
//handle wake up case
while(Serial.available() < 5); //wait the command
b = Serial.readBytes((char*)buffer+5, 5);
//send raw command to pn532
//get length of package :
// (PREAMBLE + START + LEN + LCS) + (TFI + DATA[0...n]) + (DCS + POSTAMBLE)
uint8_t l = buffer[8] + 2;
while(Serial.available() < l); //wait the command
//read command from uart
Serial.readBytes((char*)buffer+10, l);
//send raw command to pn532
nfc.sendRawCommandCheckAck(buffer, l+10);
//read pn532 answer
nfc.readRawCommandAnswer(buffer, l+10);
}else{
//normal case
//get length of package :
// (PREAMBLE + START + LEN + LCS) + (TFI + DATA[0...n]) + (DCS + POSTAMBLE)
uint8_t l = buffer[3] + 2;
//read command from uart
//while(Serial.available() < l); //wait the command
//Serial.readBytes((char*)buffer+5, l);
uint8_t br = l;
uint8_t* bufptr = buffer + 5;
while(br){
if(Serial.available()){
*bufptr++ = Serial.read();
--br;
}
}
//send raw command to pn532
nfc.sendRawCommandCheckAck(buffer, l+5);
//read pn532 answer
nfc.readRawCommandAnswer(buffer, l+5);
}
}
}
Used Resources
http://nfc-tools.org/index.php/Libnfc:Arduino - Used to install libnfc
https://github.com/gunmetal313/mfocuino - Uploaded the sketch uartnfc.ino and imported the libraries (mfocuino/mfocuino-read-only/nfcreader/arduino/libraries/PN532/) into the Arduino IDE.
Things I have already tried to fix the problem
Why "No NFC device found" with libnfc and PN532 SHIELD
PN532 Unable to open NFC device
https://github.com/nfc-tools/libnfc/issues/507
https://forums.adafruit.com/viewtopic.php?f=19&t=58188
https://superuser.com/questions/1409108/nfc-unable-to-open-nfc-device
I almost gave up having the same problem. For me it finally worked when using 9600 baud in the Arduino Sketch and libnfc config.
We are having a problem with the max_calls settings on PJSIP and Asterisk.
We are stress-testing our Asterisk server, but found that we had a max 32 active call limitation on our PJSIP module. We are using PJSIP to test our Asterisk server
After a quick google we found the following settings would fix the problem.
Following steps can be taken to increase number of calls supported on PJSIP:
Example: If you have to increase simultaneous calls to 1000 change the following:
1. Change PJSUA_MAX_CALLS to 1000 and PJSUA_MAX_ACC to 1000
2. Change PJ_IOQUEUE_MAX_HANDLES to 2000 (double of desired number of calls).
3. Change __FD_SETSIZE to double to 2000 (double of desired number of calls).
4. Change PJSUA_MAX_PLAYERS to 1000.
5. Recompile pjsip using following steps:
a. ./configure --disable-ssl --disable-sound;
b. make dep
c. make
d. make install
6. Recompile your application with new libs.
Somehow This is not working for us;
What are we doing wrong here?
Anybody suggestions. Help would be higly appreciated.
Our code in the config_site.php file
/*
* This file contains several sample settings especially for Windows
* Mobile and Symbian targets. You can include this file in your
* <pj/config_site.h> file.
*
* The Windows Mobile and Symbian settings will be activated
* automatically if you include this file.
*
* In addition, you may specify one of these macros (before including
* this file) to activate additional settings:
*
* #define PJ_CONFIG_NOKIA_APS_DIRECT
* Use this macro to activate the APS-Direct feature. Please see
* http://trac.pjsip.org/repos/wiki/Nokia_APS_VAS_Direct for more
* info.
*
* #define PJ_CONFIG_WIN32_WMME_DIRECT
* Configuration to activate "APS-Direct" media mode on Windows or
* Windows Mobile, useful for testing purposes only.
*/
/*
* Typical configuration for WinCE target.
*/
#if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
/*
* PJLIB settings.
*/
/* Disable floating point support */
#define PJ_HAS_FLOATING_POINT 0
/*
* PJMEDIA settings
*/
/* Select codecs to disable */
#define PJMEDIA_HAS_L16_CODEC 0
#define PJMEDIA_HAS_ILBC_CODEC 0
/* We probably need more buffers on WM, so increase the limit */
#define PJMEDIA_SOUND_BUFFER_COUNT 32
/* Fine tune Speex's default settings for best performance/quality */
#define PJMEDIA_CODEC_SPEEX_DEFAULT_QUALITY 5
/* For CPU reason, disable speex AEC and use the echo suppressor. */
#define PJMEDIA_HAS_SPEEX_AEC 0
/* Previously, resampling is disabled due to performance reason and
* this condition prevented some 'light' wideband codecs (e.g: G722.1)
* to work along with narrowband codecs. Lately, some tests showed
* that 16kHz <-> 8kHz resampling using libresample small filter was
* affordable on ARM9 260 MHz, so here we decided to enable resampling.
* Note that it is important to make sure that libresample is created
* using small filter. For example PJSUA_DEFAULT_CODEC_QUALITY must
* be set to 3 or 4 so pjsua-lib will apply small filter resampling.
*/
//#define PJMEDIA_RESAMPLE_IMP PJMEDIA_RESAMPLE_NONE
#define PJMEDIA_RESAMPLE_IMP PJMEDIA_RESAMPLE_LIBRESAMPLE
/* Use the lighter WSOLA implementation */
#define PJMEDIA_WSOLA_IMP PJMEDIA_WSOLA_IMP_WSOLA_LITE
/*
* PJSIP settings.
*/
/* Set maximum number of dialog/transaction/calls to minimum to reduce
* memory usage
*/
#define PJSIP_MAX_TSX_COUNT 31
#define PJSIP_MAX_DIALOG_COUNT 31
#define PJSUA_MAX_CALLS 64
/*
* PJSUA settings
*/
/* Default codec quality, previously was set to 5, however it is now
* set to 4 to make sure pjsua instantiates resampler with small filter.
*/
#define PJSUA_DEFAULT_CODEC_QUALITY 4
/* Set maximum number of objects to minimum to reduce memory usage */
#define PJSUA_MAX_ACC 64
#define PJSUA_MAX_PLAYERS 64
#define PJSUA_MAX_RECORDERS 4
#define PJSUA_MAX_CONF_PORTS (PJSUA_MAX_CALLS+2*PJSUA_MAX_PLAYERS)
#define PJSUA_MAX_BUDDIES 32
#endif /* PJ_WIN32_WINCE */
/*
* Typical configuration for Symbian OS target
*/
#if defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0
/*
* PJLIB settings.
*/
/* Disable floating point support */
#define PJ_HAS_FLOATING_POINT 0
/* Misc PJLIB setting */
#define PJ_MAXPATH 80
/* This is important for Symbian. Symbian lacks vsnprintf(), so
* if the log buffer is not long enough it's possible that
* large incoming packet will corrupt memory when the log tries
* to log the packet.
*/
#define PJ_LOG_MAX_SIZE (PJSIP_MAX_PKT_LEN+500)
/* Since we don't have threads, log buffer can use static buffer
* rather than stack
*/
#define PJ_LOG_USE_STACK_BUFFER 0
/* Disable check stack since it increases footprint */
#define PJ_OS_HAS_CHECK_STACK 0
/*
* PJMEDIA settings
*/
/* Disable non-Symbian audio devices */
#define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
#define PJMEDIA_AUDIO_DEV_HAS_WMME 0
/* Select codecs to disable */
#define PJMEDIA_HAS_L16_CODEC 0
#define PJMEDIA_HAS_ILBC_CODEC 0
#define PJMEDIA_HAS_G722_CODEC 0
/* Fine tune Speex's default settings for best performance/quality */
#define PJMEDIA_CODEC_SPEEX_DEFAULT_QUALITY 5
/* For CPU reason, disable speex AEC and use the echo suppressor. */
#define PJMEDIA_HAS_SPEEX_AEC 0
/* Previously, resampling is disabled due to performance reason and
* this condition prevented some 'light' wideband codecs (e.g: G722.1)
* to work along with narrowband codecs. Lately, some tests showed
* that 16kHz <-> 8kHz resampling using libresample small filter was
* affordable on ARM9 222 MHz, so here we decided to enable resampling.
* Note that it is important to make sure that libresample is created
* using small filter. For example PJSUA_DEFAULT_CODEC_QUALITY must
* be set to 3 or 4 so pjsua-lib will apply small filter resampling.
*/
//#define PJMEDIA_RESAMPLE_IMP PJMEDIA_RESAMPLE_NONE
#define PJMEDIA_RESAMPLE_IMP PJMEDIA_RESAMPLE_LIBRESAMPLE
/* Use the lighter WSOLA implementation */
#define PJMEDIA_WSOLA_IMP PJMEDIA_WSOLA_IMP_WSOLA_LITE
/* We probably need more buffers especially if MDA audio backend
* is used, so increase the limit
*/
#define PJMEDIA_SOUND_BUFFER_COUNT 32
/*
* PJSIP settings.
*/
/* Disable safe module access, since we don't use multithreading */
#define PJSIP_SAFE_MODULE 0
/* Use large enough packet size */
#define PJSIP_MAX_PKT_LEN 2000
/* Symbian has problem with too many large blocks */
#define PJSIP_POOL_LEN_ENDPT 1000
#define PJSIP_POOL_INC_ENDPT 1000
#define PJSIP_POOL_RDATA_LEN 2000
#define PJSIP_POOL_RDATA_INC 2000
#define PJSIP_POOL_LEN_TDATA 2000
#define PJSIP_POOL_INC_TDATA 512
#define PJSIP_POOL_LEN_UA 2000
#define PJSIP_POOL_INC_UA 1000
#define PJSIP_POOL_TSX_LAYER_LEN 256
#define PJSIP_POOL_TSX_LAYER_INC 256
#define PJSIP_POOL_TSX_LEN 512
#define PJSIP_POOL_TSX_INC 128
/*
* PJSUA settings.
*/
/* Default codec quality, previously was set to 5, however it is now
* set to 4 to make sure pjsua instantiates resampler with small filter.
*/
#define PJSUA_DEFAULT_CODEC_QUALITY 4
/* Set maximum number of dialog/transaction/calls to minimum */
#define PJSIP_MAX_TSX_COUNT 31
#define PJSIP_MAX_DIALOG_COUNT 31
#define PJSUA_MAX_CALLS 64
/* Other pjsua settings */
#define PJSUA_MAX_ACC 64
#define PJSUA_MAX_PLAYERS 64
#define PJSUA_MAX_RECORDERS 4
#define PJSUA_MAX_CONF_PORTS (PJSUA_MAX_CALLS+2*PJSUA_MAX_PLAYERS)
#define PJSUA_MAX_BUDDIES 32
#endif
/*
* Additional configuration to activate APS-Direct feature for
* Nokia S60 target
*
* Please see http://trac.pjsip.org/repos/wiki/Nokia_APS_VAS_Direct
*/
#ifdef PJ_CONFIG_NOKIA_APS_DIRECT
/* MUST use switchboard rather than the conference bridge */
#define PJMEDIA_CONF_USE_SWITCH_BOARD 1
/* Enable APS sound device backend and disable MDA & VAS */
#define PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA 0
#define PJMEDIA_AUDIO_DEV_HAS_SYMB_APS 1
#define PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS 0
/* Enable passthrough codec framework */
#define PJMEDIA_HAS_PASSTHROUGH_CODECS 1
/* And selectively enable which codecs are supported by the handset */
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMU 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMA 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_G729 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC 1
#endif
/*
* Additional configuration to activate VAS-Direct feature for
* Nokia S60 target
*
* Please see http://trac.pjsip.org/repos/wiki/Nokia_APS_VAS_Direct
*/
#ifdef PJ_CONFIG_NOKIA_VAS_DIRECT
/* MUST use switchboard rather than the conference bridge */
#define PJMEDIA_CONF_USE_SWITCH_BOARD 1
/* Enable VAS sound device backend and disable MDA & APS */
#define PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA 0
#define PJMEDIA_AUDIO_DEV_HAS_SYMB_APS 0
#define PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS 1
/* Enable passthrough codec framework */
#define PJMEDIA_HAS_PASSTHROUGH_CODECS 1
/* And selectively enable which codecs are supported by the handset */
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMU 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMA 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_G729 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC 1
#endif
/*
* Configuration to activate "APS-Direct" media mode on Windows,
* useful for testing purposes only.
*/
#ifdef PJ_CONFIG_WIN32_WMME_DIRECT
/* MUST use switchboard rather than the conference bridge */
#define PJMEDIA_CONF_USE_SWITCH_BOARD 1
/* Only WMME supports the "direct" feature */
#define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
#define PJMEDIA_AUDIO_DEV_HAS_WMME 1
/* Enable passthrough codec framework */
#define PJMEDIA_HAS_PASSTHROUGH_CODECS 1
/* Only PCMA and PCMU are supported by WMME-direct */
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMU 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMA 1
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR 0
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_G729 0
#define PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC 0
#endif
/*
* iPhone sample settings.
*/
#if PJ_CONFIG_IPHONE
/*
* PJLIB settings.
*/
/* Both armv6 and armv7 has FP hardware support.
* See https://trac.pjsip.org/repos/ticket/1589 for more info
*/
#define PJ_HAS_FLOATING_POINT 1
/*
* PJMEDIA settings
*/
/* We have our own native CoreAudio backend */
#define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
#define PJMEDIA_AUDIO_DEV_HAS_WMME 0
#define PJMEDIA_AUDIO_DEV_HAS_COREAUDIO 1
/* The CoreAudio backend has built-in echo canceller! */
#define PJMEDIA_HAS_SPEEX_AEC 0
/* Disable some codecs */
#define PJMEDIA_HAS_L16_CODEC 0
#define PJMEDIA_HAS_G722_CODEC 0
/* Use the built-in CoreAudio's iLBC codec (yay!) */
#define PJMEDIA_HAS_ILBC_CODEC 1
#define PJMEDIA_ILBC_CODEC_USE_COREAUDIO 1
/* Fine tune Speex's default settings for best performance/quality */
#define PJMEDIA_CODEC_SPEEX_DEFAULT_QUALITY 5
/*
* PJSIP settings.
*/
/* Increase allowable packet size, just in case */
//#define PJSIP_MAX_PKT_LEN 2000
/*
* PJSUA settings.
*/
/* Default codec quality, previously was set to 5, however it is now
* set to 4 to make sure pjsua instantiates resampler with small filter.
*/
#define PJSUA_DEFAULT_CODEC_QUALITY 4
/* Set maximum number of dialog/transaction/calls to minimum */
#define PJSIP_MAX_TSX_COUNT 31
#define PJSIP_MAX_DIALOG_COUNT 31
#define PJSUA_MAX_CALLS 64
/* Other pjsua settings */
#define PJSUA_MAX_ACC 64
#define PJSUA_MAX_PLAYERS 64
#define PJSUA_MAX_RECORDERS 4
#define PJSUA_MAX_CONF_PORTS (PJSUA_MAX_CALLS+2*PJSUA_MAX_PLAYERS)
#define PJSUA_MAX_BUDDIES 32
#endif
/*
* Android sample settings.
*/
#if PJ_CONFIG_ANDROID
#define PJ_ANDROID 1
/*
* PJLIB settings.
*/
/* Disable floating point support */
#undef PJ_HAS_FLOATING_POINT
#define PJ_HAS_FLOATING_POINT 0
/*
* PJMEDIA settings
*/
/* We have our own OpenSL ES backend */
#define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
#define PJMEDIA_AUDIO_DEV_HAS_WMME 0
#define PJMEDIA_AUDIO_DEV_HAS_OPENSL 0
#define PJMEDIA_AUDIO_DEV_HAS_ANDROID_JNI 1
/* Disable some codecs */
#define PJMEDIA_HAS_L16_CODEC 0
#define PJMEDIA_HAS_G722_CODEC 0
/* Fine tune Speex's default settings for best performance/quality */
#define PJMEDIA_CODEC_SPEEX_DEFAULT_QUALITY 5
/*
* PJSIP settings.
*/
/* Increase allowable packet size, just in case */
//#define PJSIP_MAX_PKT_LEN 2000
/*
* PJSUA settings.
*/
/* Default codec quality, previously was set to 5, however it is now
* set to 4 to make sure pjsua instantiates resampler with small filter.
*/
#define PJSUA_DEFAULT_CODEC_QUALITY 4
/* Set maximum number of dialog/transaction/calls to minimum */
#define PJSIP_MAX_TSX_COUNT 31
#define PJSIP_MAX_DIALOG_COUNT 31
#define PJSUA_MAX_CALLS 64
/* Other pjsua settings */
#define PJSUA_MAX_ACC 64
#define PJSUA_MAX_PLAYERS 64
#define PJSUA_MAX_RECORDERS 4
#define PJSUA_MAX_CONF_PORTS (PJSUA_MAX_CALLS+2*PJSUA_MAX_PLAYERS)
#define PJSUA_MAX_BUDDIES 32
#endif
/*
* BB10
*/
#if defined(PJ_CONFIG_BB10) && PJ_CONFIG_BB10
/* Quality 3 - 4 to use resampling small filter */
#define PJSUA_DEFAULT_CODEC_QUALITY 4
#define PJMEDIA_HAS_LEGACY_SOUND_API 0
#undef PJMEDIA_HAS_SPEEX_AEC
#define PJMEDIA_HAS_SPEEX_AEC 0
#undef PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO
#define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
#endif
/*
* Minimum size
*/
#ifdef PJ_CONFIG_MINIMAL_SIZE
# undef PJ_OS_HAS_CHECK_STACK
# define PJ_OS_HAS_CHECK_STACK 0
# define PJ_LOG_MAX_LEVEL 0
# define PJ_ENABLE_EXTRA_CHECK 0
# define PJ_HAS_ERROR_STRING 0
# undef PJ_IOQUEUE_MAX_HANDLES
/* Putting max handles to lower than 32 will make pj_fd_set_t size smaller
* than native fdset_t and will trigger assertion on sock_select.c.
*/
# define PJ_IOQUEUE_MAX_HANDLES 128
# define PJ_CRC32_HAS_TABLES 0
# define PJSIP_MAX_TSX_COUNT 15
# define PJSIP_MAX_DIALOG_COUNT 15
# define PJSIP_UDP_SO_SNDBUF_SIZE 4000
# define PJSIP_UDP_SO_RCVBUF_SIZE 4000
# define PJMEDIA_HAS_ALAW_ULAW_TABLE 0
#elif defined(PJ_CONFIG_MAXIMUM_SPEED)
# define PJ_SCANNER_USE_BITWISE 0
# undef PJ_OS_HAS_CHECK_STACK
# define PJ_OS_HAS_CHECK_STACK 0
# define PJ_LOG_MAX_LEVEL 3
# define PJ_ENABLE_EXTRA_CHECK 0
# define PJ_IOQUEUE_MAX_HANDLES 5000
# define PJSIP_MAX_TSX_COUNT ((640*1024)-1)
# define PJSIP_MAX_DIALOG_COUNT ((640*1024)-1)
# define PJSIP_UDP_SO_SNDBUF_SIZE (24*1024*1024)
# define PJSIP_UDP_SO_RCVBUF_SIZE (24*1024*1024)
# define PJ_DEBUG 0
# define PJSIP_SAFE_MODULE 0
# define PJ_HAS_STRICMP_ALNUM 0
# define PJ_HASH_USE_OWN_TOLOWER 1
# define PJSIP_UNESCAPE_IN_PLACE 1
# if defined(PJ_WIN32) || defined(PJ_WIN64)
# define PJSIP_MAX_NET_EVENTS 10
# endif
# define PJSUA_MAX_CALLS 512
#endif
To Change the calls limit in PJSIP:
1---
Go to
vim /home/administrator/pjproject-2.8/pjlib/include/pj/config_site.h
#define PJSUA_MAX_CALLS 400
#define PJSUA_MAX_ACC 400
#define PJ_IOQUEUE_MAX_HANDLES 400
#define __FD_SETSIZE 800
#define PJSUA_MAX_PLAYERS 400
2--
Go to
vim pjproject-2.8\pjproject-2.8\pjsip\src\pjsua-lib\pjsua_core.c
cfg->max_calls = ((PJSUA_MAX_CALLS) < 400) ? (PJSUA_MAX_CALLS) : 400;
I am trying to implement Modbus TCP on arduino uno + ethernet shield using the following code.
I am using a modbus slave simulator on a pc to check the following code. However, the code doesn't seem to be working. I have downloaded the code & the libraries from http://myarduinoprojects.com/modbus.html. Please suggest me corrections if necessary. Also is there another working example available for modbus tcp/ip on arduino.
Thanks.
#include <SPI.h>
#include <Ethernet.h>
#include "MgsModbus.h"
MgsModbus Mb;
int inByte = 0; // incoming serial byte
// Ethernet settings (depending on MAC and Local network)
byte mac[] = {0x00, 0x1A, 0xB6, 0x02, 0xD1, 0x14 };
IPAddress ip(192, 168, 0, 35);
void setup()
{
// serial setup
Serial.begin(9600);
Serial.println("Serial interface started");
// initialize the ethernet device
Ethernet.begin(mac, ip); // start etehrnet interface
Serial.println("Ethernet interface started");
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
// slave address
Mb.remSlaveIP = (192,168,0,1);
// Fill MbData
// Mb.SetBit(0,false);
Mb.MbData[0] = 1;
Mb.MbData[1] = 2;
Mb.MbData[2] = 3;
Mb.MbData[3] = 4;
Mb.MbData[4] = 5;
Mb.MbData[5] = 6;
Mb.MbData[6] = 0;
Mb.MbData[7] = 0;
Mb.MbData[8] = 0;
Mb.MbData[9] = 0;
Mb.MbData[10] = 0;
Mb.MbData[11] = 0;
// print MbData
for (int i=0;i<12;i++) {
Serial.print("address: "); Serial.print(i); Serial.print("Data: "); Serial.println(Mb.MbData[i]);
}
// print menu
Serial.println("0 - print the first 12 words of the MbData space");
Serial.println("1 - FC 1 - read the first 5 coils from the slave and store them in the lower byte of MbData[1]");
Serial.println("2 - FC 2 - read the first 5 discrete inputs from the slave and store them in the higer of the MbData[1]");
Serial.println("3 - FC 3 - read the first 5 registers from the slave and store them in MbData[3..7");
Serial.println("4 - FC 4 - read the first 5 input registers from the slave and store them in MbData[8..12]");
Serial.println("5 - FC 5 - write coil 0 of the slave with the bit valeu of MbData[0.0]");
Serial.println("6 - FC 6 - write register 0 of the slave with MbData[2]");
Serial.println("7 - FC 15 - write 5 coils of the slave starting with coil 0 with GetBit(16..20");
Serial.println("8 - Fc 16 - write 5 registers of the slave starting on register 0 with MbData[0..4]");
Serial.println(Mb.remSlaveIP);
}
void loop()
{
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
if (inByte == '0') { // print MbData
for (int i=0;i<12;i++) {
Serial.print("address: "); Serial.print(i); Serial.print("Data: "); Serial.println(Mb.MbData[i]);
}
}
if (inByte == '1') {Mb.Req(MB_FC_READ_COILS, 6,6,6);} // 1 // ref, count, pos
if (inByte == '2') {Mb.Req(MB_FC_READ_DISCRETE_INPUT, 6,6,6);} // 2
if (inByte == '3') {Mb.Req(MB_FC_READ_REGISTERS, 6,6,6);} // 3
if (inByte == '4') {Mb.Req(MB_FC_READ_INPUT_REGISTER, 6,6,6);} // 4
if (inByte == '5') {Mb.Req(MB_FC_WRITE_COIL, 0,0,0);} // 5 // count can be x
if (inByte == '6') {Mb.Req(MB_FC_WRITE_REGISTER, 7,0,0);} // 6 // count can be x
if (inByte == '7') {Mb.Req(MB_FC_WRITE_MULTIPLE_COILS, 0,6,0);} // 15
if (inByte == '8') {Mb.Req(MB_FC_WRITE_MULTIPLE_REGISTERS, 0,6,0);} // 16
}
Mb.MbmRun();
// Mb.MbsRun();
}
Serial monitor works fine. Following lines are printed on first debugging the program
Serial interface started
Ethernet interface started
My IP address: 192.168.0.35.
address: 0Data: 1
address: 1Data: 2
address: 2Data: 3
address: 3Data: 4
address: 4Data: 5
address: 5Data: 6
address: 6Data: 0
address: 7Data: 0
address: 8Data: 0
address: 9Data: 0
address: 10Data: 0
address: 11Data: 0
0 - print the first 12 words of the MbData space
1 - FC 1 - read the first 5 coils from the slave and store them in the lower byte of MbData[1]
2 - FC 2 - read the first 5 discrete inputs from the slave and store them in the higer of the MbData[1]
3 - FC 3 - read the first 5 registers from the slave and store them in MbData[3..7
4 - FC 4 - read the first 5 input registers from the slave and store them in MbData[8..12]
5 - FC 5 - write coil 0 of the slave with the bit valeu of MbData[0.0]
6 - FC 6 - write register 0 of the slave with MbData[2]
7 - FC 15 - write 5 coils of the slave starting with coil 0 with GetBit(16..20
8 - Fc 16 - write 5 registers of the slave starting on register 0 with MbData[0..4]
1.0.0.0
however it seems that the TCP communication does not work since there is nothing on the serial monitor after this #graham.reeds
I am using mgsmodbus for my modbuswork at office. What I have is a Master TI board and a Slave simulator. However I am using Wifi.h instead of ethernet.h. I am able to do all the operations.
Did you check if the ethernet connection is properly established?
If so try IBH Modbus slave simulator. That works perfect. You would have to change the setting to TCP and select the port. Sometimes the port number you are trying for could be wrong. I use port 502 which is the default one.
Also, make sure that the slave IP in the .cpp code is also changed.
In my Qt application, I am using QNetworkAccessManager in a Thread so as to keep my main thread free to do its task. For every get operation that I do, I am storing the QNetworkReply* in a list and upon a response, I retrieve it from my list, delete the entry in the list and call deleteLater() on the QNetworkReply* object. However, after a couple of request/responses here is the crash i get in runtime:
The code that I used is:
void NetworkManager::responseFromServer(QNetworkReply* pReply)
{
// Retrieve the TileRequestMessage.
QImage *pImage = imageMapper.value(pReply);
// Get the bytes from the response.
QByteArray byteArray = pReply->readAll();
// Load the QImage with the data.
bool loaded = pImage->loadFromData(byteArray);
// Remove the request from book-keeping.
imageMapper.remove(mapIterator.key());
pReply->deleteLater();
return;
}
where pImage is a pointer to a object of type QImage. The Object is created in advance and its pointer mapped to a QNetworkReply* is stored in a QMap.
The error I get is:
Stopped at 0x637837aa (operator delete) in thread 1 (missing debug information).
sException at 0x637837aa, code: 0xc0000005: read access violation at: 0xffffffffcdcdcdc1,
flags=0x0
The call stack is:
0 operator delete MSVCR90D 0 0x637837aa
1 QList::node_destruct qlist.h 418 0x64071704
2 QList::free qlist.h 744 0x6407153b
3 QList::~QList qlist.h 718 0x64070b1f
4 QQueue::~QQueue qqueue.h 58 0x6407076f
5 QNetworkReplyImplPrivate::handleNotifications qnetworkreplyimpl.cpp 358 0x6406c99d
6 QNetworkReplyImpl::event qnetworkreplyimpl.cpp 868 0x6406e646
7 QApplicationPrivate::notify_helper qapplication.cpp 4445 0x6507153e
8 QApplication::notify qapplication.cpp 3845 0x6506f1ba
9 QCoreApplication::notifyInternal qcoreapplication.cpp 732 0x671c2fb1
10 QCoreApplication::sendEvent qcoreapplication.h 215 0x671c8159
11 QCoreApplicationPrivate::sendPostedEvents qcoreapplication.cpp 1373 0x671c3f0b
12 qt_internal_proc qeventdispatcher_win.cpp 506 0x67206bf9
13 IsThreadDesktopComposited USER32 0 0x77bb86ef
14 IsThreadDesktopComposited USER32 0 0x77bb8876
15 IsThreadDesktopComposited USER32 0 0x77bb89b5
16 DispatchMessageW USER32 0 0x77bb8e9c
17 QEventDispatcherWin32::processEvents qeventdispatcher_win.cpp 807 0x67207b96
18 QEventLoop::processEvents qeventloop.cpp 150 0x671c0abe
19 QEventLoop::exec qeventloop.cpp 201 0x671c0bf0
20 QThread::exec qthread.cpp 490 0x670643d6
21 DispatcherThread::run DispatcherThread.cpp 226 0x1001031a
22 QThreadPrivate::start qthread_win.cpp 317 0x6706852f
23 beginthreadex MSVCR90D 0 0x636edff3
24 beginthreadex MSVCR90D 0 0x636edf89
25 BaseThreadInitThunk kernel32 0 0x77191194
26 RtlInitializeExceptionChain ntdll 0 0x77ccb429
27 RtlInitializeExceptionChain ntdll 0 0x77ccb3fc
I am using msvc to compile my Qt code. Any heads-up on what the problem might be ??
Thanks,
Vishnu.
Without looking at your actual code and based on your error description, it could be possible that you are deleting the QNetworkReply before it has emitted the finished signal. So after the deletion when new data becomes available - QNetworkReply emits the readyRead signal which is when it would be trying to access the already deleted entry and hence the "read access violation" errors.
Just an idea:
Since you use deleteLater() you do not know when the delete will take place and thus when the pointer QNetworkReply* may be invalid in your list.
Thus, maybe try wrapping your pointer in a guared pointer (QPointer) and then just remove it from the list if it deleted/null. If it's still a valid pointer you call deleteLater();