SMS sent with AT Command has random sender number - gsm

I've got a SIM7600G-H version 2. I want to use it to send and receive SMSes and phone calls through my PC. I've got it connected with a USB cable and I'm writing Kotlin code to communicate with jssc.
It's important to know...
I have a UK SIM card (the provider is Giffgaff)
I'm in the Netherlands, so I'm roaming.
SMS
I can use AT Commands to successfully send SMS messages...
> AT+CMGS="+31600..."
> test message \u001a
+CMGS: 55
But when I receive them, the sender number is completely random, and from different countries.
I don't recognise any of the numbers. I don't know where they come from.
Phone calls
I'm also unable to make phone calls.
> ATD+31600....
NO CARRIER
Questions
How can I make sure that when I send SMSes with my SIM7600 that they appear as the correct number?
How can I configure the SIM7600 to make phone calls?
Diagnostics
The 'net light pin' LED usually flashes 200ms on, 200ms (4G registered), which seems fine.
AT+CEER usually returns +CEER: No cause information available, and sometimes returns bearer capability not authorized
AT+CUSD=1 -> OK and ATD*#5005*7672# takes about 30 seconds to always reports NO CARRIER
Device details
> ATI
Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM7600G-H
Revision: SIM7600M22_V2.0
IMEI: 812[omitted]
+GCAP: +CGSM
Network info
The network settings seem okay. Correct carrier name and details, decent signal quality, roaming, LTE.
> AT+CSPN?
+CSPN : "giffgaff",1
> AT+COPS?
+COPS : 0,0,"NL KPN giffgaff",7
> AT+CSQ
+CSQ : 25,99
> AT+CREG?
+CEREG : 0,5
> AT+CEREG?
+CEREG: 0,4
> AT+CNSMOD?
+CNSMOD : 0,8
+CIMI : 123...[omitted] # looks okay
+CPSI : LTE,Online,204-08,0xF03D,4098848,203,EUTRAN-BAND3,1300,5,5,-88,-946,-658,12
PDP / APN
I've tried setting the APN to Giffgaff settings, and I think they're set correctly, using.
APN: giffgaff.com
Username: gg
Password: p
Proxy: {Leave Blank}
MCC: 234
MNC: 10
APN protocol: IPv4v6
APN roaming protocol: IPv4
Authentication type: PAP
+CGDCONT : 1,"IPV4V6","giffgaff.com","0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0",0,0,0,0
+CGDCONT : 2,"IP","giffgaff.com","0.0.0.0",0,0,0,0
+CGDSCONT : # (no output)
+CGACT : 1,0
+CGACT : 2,1
The SMS Service Center number seems correct
+CSCA: "+447802002606",145
AT&V - Display current configuration
> AT&V
&C: 2; &D: 2; &E: 1; &F: 0; &S: 0; &W: 0; E: 1; L: 0; M: 0; Q: 0; V: 1;
X: 1; Z: 0; \Q: 3; \S: 0; \V: 0; O: 0; S0: 0; S2: 43; S3: 13; S4: 10;
S5: 8; S6: 2; S7: 0; S8: 2; S9: 6; S10: 14; S11: 95; S30: 0; S103: 1;
S104: 1; +FCLASS: 0; +ICF: 3,3; +IFC: 0,0; +IPR: 115200; +DR: 0;
+DS: 0,0,2048,6; +CMEE: 2; +WS46: 25; +CFUN:; +IPREX: 115200;
+CBST: 0,0,1; +CRLP: (61,61,48,6,0),(61,61,48,6,1),(240,240,52,6,2);
+CV120: 1,1,1,0,0,0; +CHSN: 0,0,0,0; +CSSN: 0,0; +CREG: 0; +CGREG: 0;
+CEREG: 0; +CSCS: "IRA"; +CSTA: 129; +CR: 0; +CRC: 0;
+CGDCONT: (1,"IPV4V6","giffgaff.com","0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0",0,0,0,0),(2,"IP","giffgaff.com","0.0.0.0",0,0,0,0);
+CGDSCONT: ; +CGTFT: ; +CGEQREQ: ; +CGEQMIN: ; +CGEQOS: ; +CGQREQ: ;
+CGQMIN: ; +CGEREP: 0,0; +CGDATA: "PPP"; +CGCLASS: "A"; +CGPIAF: 0,0,0,0;
+CGSMS: 2; +CSMS: 0; +CMGF: 1; +CSAS: 0; +CRES: 0; +CSCA: "",;
+CSMP: ,,0,0; +CSDH: 0; +CSCB: 0,"",""; +CMGP: 4098,0,,0,; +ES: ,,;
+ESA: 0,,,,0,0,255,; +CMOD: 0; +CEMODE: 1; +CVHU: 1; ; ; ; ; ; ;
+CSCLK: 0; +CCUART: 0; +CFGRI: 0,60,120; +CUARTSD: 500; +CURCD: 0;
+CUARTLOG: 0; +CUARTRM: 0; +CFGRIDTM: 60,120; +CATR: 0; +CNMP: 2;
+CNRP: 255; +CNAOP: 0; +CNSDP: 2; +CNSMOD: 0; +CNLSA: 0; +CEXTEPLMN: 1;
+CSQFMT: 1; +AUTOCSQ: 0,0; +CSQDELTA: 5; +CPSI: 0; +CMGSI: 2;
+CMGRMI: 4,0; +MONI: 0; +CRUPSI: 0; +CRUSET: 0; +CGPS: 0,1; +CGPSMSB: 1;
+CGPSINFO: 0; +CGPSINFOCFG: 0,0,0; +CGPSHOR: 50; +CGPSPMD: 65407;
+CGPSXD: 0; +CGNSSINFO: 0; +CSOCKAUTH: 1,0,""; +CGAUTH: 1,0,""; ;
+CIPHEAD: 1; +CIPSRIP: 1; +CIPCCFG: 10,0,0,1,0,0,500; +CIPENSRXGET: 0;
+CIPMODE: 0; +CPIN: ��������,��������; +CMEC: 0,0,0,0;
+CIND: 0,4,1,1,1,0,1,0; +CMER: 0,0,0,0,0; +CGATT: 1; +CGACT(1,0),(2,1);
+CPBS: "SM"; +CPMS: "SM","SM","SM"; +CNMI: 2,1,0,0,0; +CMMS: 0;
+CCUG: 0,0,0; +COPS: 0,0,""; +CUSD: 1; +CAOC: 1; +CCWA: 0;
+CPOL: 0,2,"",0,0,0,0; +CPLS: 0; +CTZR: 0; +CTZU: 0; +CLIP: 0; +COLP: 0;
+CDIP: 0; +CLIR: 0; +CSDF: 1; +CEN: 0; +CPSMS: 0,"","","","";
+CEDRXS: 0,1,""; +CCARDMA: 0; +STK: 0; +CSALPHA: 0; +MORING: 0;
+CWAKEUPSMSSWITCH: 0; +CFILTERSMSSWITCH: 0; +EB: 1,0,30; +EFCS: 1;
+ER: 0; +ESR: 1; +ETBM: 1,1,20; +MA: ; +MR: 0; +MS: ; +MV18R: 0;
+MV18S: 0,0,0; +CXT: 0; +CDR: 0; +CDS: 0,1,2048,6; +CFC: 0; +CFG: "";
+CQD: 10; +CCRC: 0; +QCMUX: C,2; +CTA: 0; +ILRR: 0; +QCPIN: ,; *CNTI: 0;
^PREFMODE: 0; ^DSCI: 0; ^MODE: 0; ^CPIN: ,
OK
Update 1
# try finding own number
> AT+CNUM?
ERROR
# check the command does exist
> AT+CNUM=?
OK
# current phonebook
> AT+CPBS?
+CPBS: "SM",4,100
# show possible phonebooks
> AT+CPBS=?
+CPBS: ("SM","DC","FD","LD","MC","ME","RC","EN","ON")
# switch to ON (MSISDN list)
> AT+CPBS=ON
ERROR
# ON needs to be in quotes
> AT+CPBS="ON"
OK
# find by text (if null, will list all entries)
# none available
> AT+CPBF=
ERROR
# show valid indexes
> AT+CPBR=?
+CPBR: (1-3),40,14
# can't find any numbers
> AT+CPBR=1,3
+CME ERROR: not found
# store my number
> AT+CPBW=,"+4470..."
OK
#
> AT+CPBS?
+CPBS: "ON",1,3
# fetch first index
> AT+CPBR=1
+CPBR: 1,"+4470...",145,""
# find by text now returns my number
> AT+CPBF=
+CPBF: 1,"+4470...",145,""
# my number is now correctly returned
> AT+CNUM
+CPBR: 1,"+4470...",145,""
All looks good, but it still doesn't work.
The status light shows that it is reconnecting, and then settles into a 200ms/200ms on/off cycle.
> AT+CMGS="+3160..."
> asd \u001a
The status light then turns solid red (searching for network).
Eventually (~ 2 minutes later) it returns
+CMS ERROR: Unknown error
> AT+CEER
+CEER: EMM attach failed
Status info
> ATD*#5005*7672#
NO CARRIER # takes around 30 seconds to return
> AT+COPS?
+COPS: 0,0,"NL KPN giffgaff",0
> AT+CSQ
+CSQ: 19,99
> AT+CREG?
+CREG: 2,5,1806,AC07E0
> AT+CEREG?
+CEREG: 0,4
> AT+CNSMOD?
+CNSMOD : 0,7
> AT+CPSI?
+CPSI: WCDMA,Online,204-08,0x1806,11274208,WCDMA 900,233,3011,0,4.0,76,20,38,500
> AT+CGACT?
+CGACT: 1,0
+CGACT: 2,0
# activate 2nd PDP (it's Giffgaff's roaming one)
> AT+CGACT=1,2
OK
> AT+CGACT?
+CGACT: 1,0
+CGACT: 2,1
> AT+CREG?
+CREG: 5,1806,AC07E0

As per location
I have a UK SIM card (the provider is Giffgaff)
I'm in the Netherlands, so I'm roaming.
this looks like a behavior of the roaming arrangement Giffgaff has with the local provider.
however if your modem supports AT+CNUM then it should return returns the MSISDNs related to the subscriber
here is a example from https://iot-developer.thalesgroup.com :
at+cnum?
+CME ERROR: unknown // response
at+cpbs? - display the active phonebook storage
+CPBS: "SM",250,250 // response
OK
at+cpbs=ON - select the active phonebook storage to MSISDN list
OK
at+cpbs? - display the active phonebook storage,
+CPBS: "ON",0,3 - MSISDN list is empty
OK
at+cpbw=,"+48723976327" - enter your own MSISDN
OK
at+cpbs? - display the active phonebook storage,
+CPBS: "ON",1,3 - MSISDN list has one item
OK
at+cpbr=1 - reading MSISDN list, position 1
+CPBR: 1,"+48723976327",145,"" - own MSISDN
OK
at+cnum
+CNUM: ,"+48723976327",145 - own MSISDN

Related

what is Program /46-0106 Error in node Veh1 on channel WLAN 1 in C2X IL CAPL function C2xGetTokenInt: Protocol "EU_ApplMsg::DENM" not found

I'm trying to write a counter which is sending a msg+CTR but when I'm running the program it's saying this type of error "Program / Model 46-0106 Error in node Veh1 on channel WLAN 1 in C2X IL CAPL function C2xGetTokenInt: Protocol "EU_ApplMsg::DENM" not found"
Please can anybody tell me what that error mean and how to fix it?
void OnC2xPacket( long channel, long dir, long radioChannel, long signalStrength, long signalQuality, long packet )
{
byte aRx_stationID;
aRx_stationID = C2xGetTokenInt(packet, "DENM", "header.stationID");
if(aRx_stationID == 222)
{
#Veh1::sVarRxDenmCounter = C2xGetTokenInt(packet, "DENM", "denm.situation.eventType.causeCode");
if(#Veh1::sVarRxDenmCounter != gRxPacketCounterNew && gRxPacketCounterInit != 1)
{
#Veh1::sVarLostPacketNumber++;
#Veh1::sVarRecieveDataAge = 0;
}
else
{
#Veh1::sVarRecieveDataAge =1;
}
gRxPacketCounterNew = ((#Veh1::sVarRxDenmCounter+1)%256);
gRxPacketCounterInit = 0;
if(#Veh1::sVarLostPacketNumber > 1000)
{
#Veh1::sVarLostPacketNumber =0;
}
}
}
I used in the capl code the CAM and DENM messages to send Tx and receive Rx and in the capl code I don't have an error found but maybe there is an infinite loop or somebody else has a piece of knowledge about that issue.

PWM settings in PIC24FJ64GA002

Good day, I am working with a PIC24FJ64GA002 microcontroller and am struggling to get the PWM working for a servo I want to use. My code is as follows:
// PIC24FJ64GA002 Configuration Bit Settings
// 'C' source line config statements
// CONFIG2
#pragma config POSCMOD = NONE // Primary Oscillator Select (Primary oscillator disabled)
#pragma config I2C1SEL = PRI // I2C1 Pin Location Select (Use default SCL1/SDA1 pins)
#pragma config IOL1WAY = ON // IOLOCK Protection (Once IOLOCK is set, cannot be changed)
#pragma config OSCIOFNC = OFF // Primary Oscillator Output Function (OSC2/CLKO/RC15 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = FRC // Oscillator Select (Fast RC Oscillator (FRC))
#pragma config SOSCSEL = SOSC // Sec Oscillator Select (Default Secondary Oscillator (SOSC))
#pragma config WUTSEL = LEG // Wake-up timer Select (Legacy Wake-up Timer)
#pragma config IESO = ON // Internal External Switch Over Mode (IESO mode (Two-Speed Start-up) enabled)
// CONFIG1
#pragma config WDTPS = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128 // WDT Prescaler (Prescaler ratio of 1:128)
#pragma config WINDIS = ON // Watchdog Timer Window (Standard Watchdog Timer enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = ON // Watchdog Timer Enable (Watchdog Timer is enabled)
#pragma config ICS = PGx1 // Comm Channel Select (Emulator EMUC1/EMUD1 pins are shared with PGC1/PGD1)
#pragma config GWRP = OFF // General Code Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF // General Code Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
/*
* File: 34660046LAB2.c
* Author: leone
*
* Created on 06 September 2021, 1:27 PM
*/
#include "p24FJ64GA002.h"
#include "xc.h"
#define _LATR15 OC1R
int main(void) {
T2CON = 0x8010;
TMR2=0;
PR2=9999;
_T2IP=4; //Default priority value
_T2IF=0; //Clears interrupt flag before interrupt
_T2IE=1; //Enables interrupt
OC1CONbits.OC = 0; // Output compare channel is disabled
OC1R = 0x1388 ; // Initialize Compare Register1 with 50% duty cycle
OC1CONbits.OCSIDL = 0; // Output capture will continue to operate in CPU Idle mode
OC1CONbits.OCFLT = 0; // No PWM Fault condition has occurred (this bit is only used when OCM<2:0> = 111)
OC1CONbits.OCTSEL = 0; // Timer2 is the clock source for output Compare
OC1CONbits.OCM = 0x6; // PWM mode on OC, Fault pin disabled
TRISBbits.TRISB15=0;
_LATB15=0;
while(1)
{
if(TMR2>OC1R)
{
_LATB15=1;
}
else
{
_LATB15=0;
}
}
return 0;
}
I programmed the T1CON to have a period of 2 ms, and the OC1R to have half that period, which should lead to a duty cycle of 50%. I am using the FRC oscillator (8MHz) and my pre-scaler values were <0,1>. I understand the it's the OC1R pin that gives the period the cycle is high, but in the datasheets they refer to it as a pin, however they don't give what pin it is (i.e. A0,A1,R15 etc.) There is also very little example code I could find explaining the how to code this well. If anyone is a PIC expert of some kind help would be very much appreciated! The datasheet for the MCU can be downloaded at https://www.microchip.com/en-us/product/PIC24FJ64GA002.
First of all configure the IO pins for PWM output, I assume you use SPDIP package and wanna use the OC1 PWM output pin:
// Unlock Registers
__builtin_write_OSCCONL(OSCCON & 0xBF);
// Configure Output Functions (Table 10-3)
// Assign OC1 To Pin RP2
RPOR1bits.RP2R = 18;
// Lock Registers
__builtin_write_OSCCONL(OSCCON | 0x40);
For the output pin configurations see the 10.4.3.2 Output Mapping section of the datasheet.
As per steps in the datasheet's 14.3 Pulse-Width Modulation Mode section:
Set the PWM period by writing to the selected Timery Period register (PRy). İf your period is 2 ms then compute the PRy register value:
#define Fosc ( 8000000 )
#define PWM_PERIOD_MS ( 2 )
#define PWM_FREQ_HZ ( 1000 / PWM_PERIOD_MS ) // In this case 500Hz
#define PRy_VALUE (uint16_t) ( (( Fosc ) / ( 4 * TMRyPS * PWM_FREQ)) - 1 )
// Somewhere in the init func or code assign the computed value for the period register
PRx = PRx_VALUE;
Set the PWM duty cycle by writing to the OCxRS register. Since you want a 50% duty cycle compute the value for OCxRS register:
#define DUTY (50)
#define DUTY_VALUE (uint16_t) ( ( 4 * ( TMRyPS - 1 ) * DUTY ) / 100 )
// Somewhere in the init func or code assign the computed value for the duty cycle register
OCxRS = DUTY_VALUE;
Write the OCxR register with the initial duty cycle. Assign the DUTY_VALUE to the OCxR register right after OCxRS assignment:
OCxR = DUTY_VALUE;
Enable interrupts, if required, for the timer and output compare modules. The output compare interrupt is required for PWM Fault pin utilization.
Configure the output compare module for one of two PWM Operation modes by writing to the Output Compare Mode bits, OCM<2:0>
(OCxCON<2:0>).
OC1CONbits.OCTSEL = 0; // Timer2 is the clock source for output Compare
OC1CONbits.OCM = 0x6; // PWM mode on OC, Fault pin disabled
Set the TMRy prescale value and enable the time base by setting TON (TyCON<15>) = 1.
T2CON = 0x0010 // Timer2 prescaler 1:8, internal clock
T2CON.TON = 1;
From now on you should have the PWM working if the above steps are done correctly. Modify your code as per instructions here. Then try it and let me know the result.
This is a complete application that builds with MPLABX v5.50 and XC16 v1.70:
/*
* File: main.c
* Author: dan1138
* Target: PIC24FJ64GA002
* Compiler: XC16 v1.70
* IDE: MPLABX v5.50
*
* Created on October 8, 2021, 1:12 PM
*
* PIC24FJ64GA002
* +-------------------:_:-------------------+
* ICD_VPP --> : 1 MCLR VDD 28 : <-- 3v3
* < > : 2 RA0/AN0 VSS 27 : <-- GND
* < > : 3 RA1/AN1 AN9/RP15/RB15 26 : < >
* ICD_PGD < > : 4 RB0/PGD1/AN2 AN6/RP14/RB14 25 : < >
* ICD_PGC < > : 5 RB1/PGC1/AN3 AN7/RP13/RB13 24 : < >
* PWM/OC1 < > : 6 RB2/RP2/SDA2/AN4 AN8/RP12/RB12 23 : < >
* < > : 7 RB3/RP3/SCL2/AN5 RP11/RB11 22 : <*>
* - > : 8 VSS RP10/RB10 21 : <*>
* < > : 9 RA2/OSCI VCAP 20 : <-- 10uF
* < > : 10 RA3/OSCO VSS 19 : <-- GND
* < > : 11 RB4/RP4 SDA1/RP9/RB9 18 : <*>
* < > : 12 RA4 SCL1/RP8/RB8 17 : <*>
* 3v3 --> : 13 VDD RP7/RB7 16 : <*>
* <*> : 14 RB5/RP5/PGD3 PGC3/RP6/RB6 15 : <*>
* +-----------------------------------------+
* DIP-28
* * Indicates 5.0 volt tolerant input pins.
*
* Description:
* Initialize the controller to use a system oscillator of 8MHz from the on chip Fast RC oscillator.
* Setup the OC1 function to provide a 4KHz square wave output on GPIO pin RB2.
*
* Notes:
* See: https://stackoverflow.com/questions/69453833/pwm-settings-in-pic24fj64ga002
*
*/
#pragma config POSCMOD = NONE, I2C1SEL = PRI, IOL1WAY = OFF, OSCIOFNC = ON
#pragma config FCKSM = CSECMD, FNOSC = FRC, SOSCSEL = SOSC, WUTSEL = LEG
#pragma config IESO = ON, WDTPS = PS32768, FWPSA = PR128, WINDIS = ON
#pragma config FWDTEN = OFF, ICS = PGx1, GWRP = OFF, GCP = OFF, JTAGEN = OFF
#include "xc.h"
/*
* Define the system oscillator frequency that this code will setup
*/
#define FSYS (8000000ul)
#define FCY (FSYS/2ul)
/*
* Initialize this PIC
*/
void PIC_Init(void) {
/* Disable all interrupt sources */
__builtin_disi(0x3FFF); /* disable interrupts for 16383 cycles */
IEC0 = 0;
IEC1 = 0;
IEC2 = 0;
IEC3 = 0;
IEC4 = 0;
__builtin_disi(0x0000); /* enable interrupts */
CLKDIV = 0x0000; /* set for 8MHz FRC clock operations */
AD1PCFG = 0xffff; /* Set for digital I/O */
CMCON = 0x0000;
_NSTDIS = 1; /* disable interrupt nesting */
TRISA = 0xFFFF;
TRISB = 0xFFFF;
}
/*
* Initialize OC1 for PWM operation on PORTB bit RB2/RP2
*/
void OC1_Init(void) {
OC1CON = 0; /* turn off OC1 */
AD1PCFGbits.PCFG4 = 1; /* make GPIO RB2/RP2/AN4 a digital I/O pin */
LATBbits.LATB2 = 0; /* make GPIO RB2/RP2/AN4 output low */
TRISBbits.TRISB2 = 0; /* make GPIO RB2/RP2/AN4 a digital output */
_RP2R = 18; /* magic number to assign OC1 to RB2, see DS39881E-page 109 */
OC1CONbits.OCTSEL = 0; /* Use TIMER2 clock input and prescaler settings as clock for PWM count register */
OC1CONbits.OCM = 0b110; /* Set OC1 for PWM mode, fault shutdown disabled */
T2CON = 0; /* turn off TIMER2 */
T2CONbits.TCKPS = 0b00; /* set TIMER2 prescale as 1:1 */
T2CONbits.TCS = 0; /* set TIMER2 clock source as FSYS/2 */
PR2 = (FCY/4000ul)-1; /* set PWM period to 4KHz */
OC1RS = (PR2+1)>>1; /* set PWM duty cycle to 50% */
T2CONbits.TON = 1; /* turn on TIMER2 */
}
/*
* main application
*/
int main(void) {
PIC_Init();
OC1_Init();
/*
* application process loop
*/
for(;;) {
/* poll for start of PWM period */
if(IFS0bits.T2IF){
IFS0bits.T2IF= 0; /* put a breakpoint here to verify PWM timing with simulator stop watch */
Nop();
Nop();
Nop();
}
}
return 0;
}
This code does run correctly with the MPLABX simulation tool. This is almost never true. IMHO the MPLABX simulator is crap.
This is screen shot of the simulation session working:
An important note on the PIC24FJ64GA002 output compare module is that it is an early silicon implementation and the newer controllers have independent period count registers for each output compare module. This means that the output compare module periods are not tied to the TIMER period on these controllers. I mention this because it really confused me.

Modbus TCP/IP on Arduino

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.

AT USSD command with Siemens TC35 working depending on the country

I tried to perform a USSD request with AT command.
My USSD command is working for a SIM from a country A but not working from a SIM from a country B.
With country A:
00:14:57| At:DEBUG: sendCommand: AT+CUSD=1,"#111#",15
00:14:57| At:DEBUG: waitResponse: AT+CUSD=1,"#111#",15OK
00:14:57| At:DEBUG: waitResponse: result = <_sre.SRE_Match object at 0x10a1b3e00>
00:15:02| At:DEBUG: waitResponse: +CUSD: 1,"Welcome my service",15>
00:15:02| At:DEBUG: waitResponse: result = <_sre.SRE_Match object at 0x109c22918>
With country B:
00:14:57| At:DEBUG: sendCommand: AT+CUSD=1,"#111#",15
00:14:57| At:DEBUG: waitResponse: AT+CUSD=1,"#111#",15
--> ERROR
Do you know what can be the issue?
EDIT:
If I active the error message: AT+CMEE=2, I get:
+CME ERROR: ss not executed
EDIT2:
If I send the short code in PDU format I get the CME Error after a OK:
AT+CUSD=1,"23198D3602"
OK
+CME ERROR: ss not executed
If I send the short code in text mode I get the CME Error after a Ok also:
AT+CUSD=1,"#144#",15
OK
+CME ERROR: ss not executed
I tried this SIM in a Huawei key and it's working. I think I missed a parameter in the TC35 configuration.
I compared the configuration:
TC35:
AT+CSCS=?
+CSCS: ("GSM","UCS2")
AT+CSCS?
+CSCS: "GSM"
AT+CSMP?
+CSMP: 17,167,0,0
Huawei:
AT+CSCS=?
+CSCS: ("IRA","GSM","UCS2")
AT+CSCS?
+CSCS: "IRA"
AT+CSMP?
+CSMP: ,,0,0
If I put the CSCS at GSM for the Huawei it's still working.
Both key have the AT+CMGF=0 configuration.
EDIT 07/10/2013:
Please find below the different configurations between the Huawei (working with the SIM) and the TC35 (not working withe the sim).
HUAWEI:
AT+COPS?
+COPS: 0,2,"20801",2
AT+CREG?
+CREG: 0,5
AT+CSQ
+CSQ: 9,99
AT&V
&C: 2; &D: 2; &F: 0; E: 1; L: 0; M: 0; Q: 0; V: 1; X: 0; Z: 0; S0: 0;
S2: 43; S3: 13; S4: 10; S5: 8; S6: 2; S7: 50; S8: 2; S9: 6; S10: 14;
S11: 95; S30: 0; S103: 1; S104: 1; +FCLASS: 0; +ICF: 3,3; +IFC: 2,2;
+IPR: 115200; +DR: 0; +DS: 0,0,2048,6; +WS46: 12; +CBST: 0,0,1;
+CRLP: (61,61,48,6,0),(61,61,48,6,1),(240,240,52,6,2);
+CV120: 1,1,1,0,0,0; +CHSN: 0,0,0,0; +CSSN: 0,0; +CREG: 0; +CGREG: 0;
+CFUN:; +CSCS: "IRA"; +CSTA: 129; +CR: 0; +CRC: 0; +CMEE: 2; +CGDCONT: (1,"IP","internet","0.0.0.0",0,0)
; +CGDSCONT: ; +CGTFT: ; +CGEQREQ: (1,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(2,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(3,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(4,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(5,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(6,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(7,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(8,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(9,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(10,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(11,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(12,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(13,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(14,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(15,4,0,0,0,0,2,0,"0E0","0E0",3,0,0),(16,4,0,0,0,0,2,0,"0E0","0E0",3,0,0)
; +CGEQMIN: ; +CGQREQ: ; +CGQMIN: ; ; +CGEREP: 0,0; +CGCLASS: "A";
+CGSMS: 1; +CSMS: 0; +CMGF: 0; +CSAS: 0; +CRES: 0;
+CSCA: "+22376000000",145; +CSMP: ,,0,0; +CSDH: 0; +CSCB: 0,"","";
+FDD: 0; +FAR: 0; +FCL: 0; +FIT: 0,0; +ES: ,,; +ESA: 0,,,,0,0,255,;
+CMOD: 0; +CVHU: 1; ; +CPIN: ........,........; +CMEC: 0,0,0; +CKPD: 1,1;
+CIND: 0,1,1,0,1,0,1,0; +CMER: 0,0,0,0,0; +CGATT: 1; +CGACT: 0;
+CPBS: "SM"; +CPMS: "SM","SM","SM"; +CNMI: 0,0,0,0,0; +CMMS: 2; +FTS: 0;
+FRS: 0; +FTH: 3; +FRH: 3; +FTM: 96; +FRM: 96; +CCUG: 0,0,0;
+COPS: 0,2,""; +CUSD: 1; +CAOC: 1; +CCWA: 0; +CCLK: ""; +CLVL: 4;
+CMUT: 0; +CPOL: 0,2,"",0,0,0; +CPLS: 0; +CTZR: 0; +CTZU: 0; +CLIP: 0;
+COLP: 0; +CDIP: 0; +CLIR: 0; ^PORTSEL: 0; ^CPIN: ........,........;
^ATRECORD: 0; ^FREQLOCK: 11796860,0; ^GLASTERR: 1; ^CVOICE: 0;
^DDSETEX: 0; ^CMSR: 0; ; ^AUTHDATA: 1,0,"",""; ^CRPN: 0,""; ^DNSP: ;
^DNSS: ; ^WPDST: 1; ^WPDOM: 0; ^WPDFR: 65536,1; ^WPQOS: 255,50;
^WNICT: 0; ; .
AT+GCAP
+GCAP: +CGSM,+DS,+ES
TC35:
AT+COPS?
+COPS: 0,0,"Orange F"
AT+CREG?
+CREG: 0,5
AT+CSQ
+CSQ: 17,99
AT&V
ACTIVE PROFILE:
E1 Q0 V1 X4 &C1 &D2 &S0 \Q0
S0:000 S3:013 S4:010 S5:008 S6:000 S7:060 S8:000 S10:002 S18:000
+CBST: 7,0,1
+CRLP: 61,61,78,6
+CR: 0
+FCLASS: 0
+CRC: 0
+CMGF: 0
+CNMI: 0,0,0,0,1
+ILRR: 0
+IPR: 0
+CMEE: 0
^SMGO: 0,1
+CSMS: 0,1,1,1
^SACM: 0,"000000","000000"
^SCKS: 0,1
+CREG: 0,5
+CLIP: 0,2
+CAOC: 0
+COPS: 0,0,"Orange F"
AT+GCAP
+GCAP: +CGSM,+FCLASS
TC35 is a SIM300 model. I would like to know if this modem is compatible with 64k sim.
For information the SIM is working on Huawei E173 and Huawei E176 key.
EDIT 08/10/2013:
I tried a SIM32k from the same country and it is working with the TC35 modem. So question is now quite simple: Is it possible to use a 64k sim with a TC35 modem
Thank you
I have same problems with MC35i. Some cards work with CUSD and DCS response 72, some card work with CUSD but DCS response must be 15 only, some card just dont work with CUSD. In last case may help AT-command ATD:
-->AT+CUSD=1,"*100#",15
<--OK
...
<--+CME ERROR: ss not executed
-->ATD"*100#;
<--OK
...
<--+CUSD: 2,"UTF16BE",72
Also you can get same problem with performing of chain USSD commands. In this case may to help adding space before symbol <CTRL+Z>:
-->ATD"*111*38#;
<--OK
...
<--+CUSD: 1,"UTF16BE(menu with list of command)",72
<-->
-->command<CTRL+Z>
<--OK
...
<--+CME ERROR: ss not executed
-->ATD"*111*38#;
<--OK
...
<--+CUSD: 1,"UTF16BE(menu with list of command)",72
<-->
-->command <CTRL+Z>
<--OK
...
<--+CUSD: 2,"UTF16BE",72

libpcap fails to capture packets after upgrading to new linux ethernet driver

I have an old system running a custom 2.6.15 kernel that uses libpcap (version 1.1.1). Recently I've changed my network card with Intel 82575EB chipset that requires me to update the driver to igb.ko (was e1000.ko). After the update, libpcap stop capturing packets. I modified a sample test code from tcpdump website that captures 1 packet and print the header information, libpcap return header.len of 1358 and header.caplen of 42, whereas in e1000 case, both packet.len and packet.caplen returns 1358. I've tried disabling MSI/MSI-X and increase the MTU but nothing works. Is there any other options I need to set to get the igb driver to work with libpcap?
Here's the sample test program (courtesy of tcpdump/libpcap team):
#include <pcap.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
pcap_t *handle; /* Session handle */
char dev[20]; /* The device to sniff on */
char errbuf[PCAP_ERRBUF_SIZE]; /* Error string */
struct bpf_program fp; /* The compiled filter */
bpf_u_int32 mask; /* Our netmask */
bpf_u_int32 net; /* Our IP */
struct pcap_pkthdr header; /* The header that pcap gives us */
const u_char *packet; /* The actual packet */
if (argc <= 1) return(1);
strcpy(dev, argv[1]);
/* Find the properties for the device */
if (pcap_lookupnet(dev, &net, &mask, errbuf) == -1) {
fprintf(stderr, "Couldn't get netmask for device %s: %s\n", dev, errbuf);
net = 0;
mask = 0;
}
/* Open the session in promiscuous mode */
handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {
fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
return(2);
}
/* Grab a packet */
packet = pcap_next(handle, &header);
/* Print its length */
printf("packet length [%d]; captured length [%d]\n", header.len, header.caplen);
/* And close the session */
pcap_close(handle);
return(0);
}
Try libpcap 1.4.0, which is currently the most recent release; there's a bug in 1.1.1 that, as I remember, could cause a packet to be supplied with a too-short caplen even though you've supplied a sufficiently-large snapshot length argument to pcap_open_live() (which you have - BUFSIZ is typically somewhere between 1K and 4K, both of which are bigger than 42, and I think it's 4K on Linux).

Resources